/*
 * 
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','opinion_list');

/*controller部分*/


//定义父controller，主要用于controller之间传递信息
authApp.controller("fcontroller",function($scope,$http){
})


//主要操作controller
authApp.controller("opinionListcontroller",function($scope,$http, $cookies, $getQueryString){
	$scope.accounttype = $cookies.get('accounttype')
	//针对此页面需要的参数 should edit
	$scope.isAddM=true;
	$scope.isAddPwd=true;
	$scope.isclickBtn=false;
	$scope.itemlist = []
	var schoolId = $getQueryString('schoolId')
	var itemId = $getQueryString('itemId')
	$scope.show = function(num,pId) {
		// var el = document.getElementById(num)
		// $scope.filelist(num,schoolId, itemId, el)

        window.location.href="/zzpg/views/agency/schoolfilldata/view_details2.html?pid="+pId+"&schoolId="+schoolId;
		
	  }
	//**********主体方法

   $scope.filelist = function(num, schoolId, itemId, el) {
	
	if (el.style.display == 'none') {
		el.style.display = 'block'
		if ($scope.itemlist.length > 0) {
			return
		}	
	} else {
		el.style.display = 'none'
		return
	}
   }

   $scope.show2 = function(num, n) {
	var el = document.getElementById('num'+n+num)
	console.log(el)
	if (el.style.display == 'none') {
		el.style.display = 'block'

	} else {
		el.style.display = 'none'
		return
	}
   }

   $scope.turnToFile = function(pId) {
	return window.open('/views/investiga/fileInfo.html?schoolId=' + schoolId + '&son_target_id=' + pId)
   }
   $scope.redirect = function(path) {
	// $http({
	// 	method:'get',
	// 	url:apis.downSchoolFile ,
	// 	params:{"path": path},
	// }).success(function(response){
	// 	if(response.code=="000000"){
	// 		//$scope.files 
	// 		//$scope.files(response.data[0].p_id)\
	// 		totext(response.data)
	// 	}else{
	// 		alert(response.errorMsg);
	// 	}
	// }).error(function(){
	// 	alert("网络出现故障，请确认网络是否连接");
	// })  
	 
     return window.location.href= apis.downloadsFile + '?path=' + path
   }

	var queryMainApi=apis.queryItemListByExpert;//！！！should edit
	$scope.queryMain=function(){
	
		$http({
			method:'get',
			url:apis.underSchoolFile ,
			params:{"school_id": schoolId, 'item_id': itemId},
		}).success(function(response){
		  if(response.code=="000000"){
			 //el.style.display == 'block'
			 $scope.itemlist = response.data
		  }else{
			 alert(response.errorMsg);
		  }
		}).error(function(){
		  alert("网络出现故障，请确认网络是否连接");
		})
	}

	$scope.queryMain();
	
	/*下面为自已编辑部分*/
	
	//调用主接口成功之后的处理方法
	$scope.queryMainApiCallBack=function(response){
		$scope.list=response.data;
	}

	$scope.turnTo=function(schoolId,itemId,index,firstName,schoolName, state){
		location.href="table4.html?schoolId="+schoolId+"&itemId="+itemId+"&index="+index+"&firstName="+toUnicode(firstName)+"&schoolName="+toUnicode(schoolName)+'&state='+state;
	}
	$scope.download=function(schoolId,itemId, schoolName){
		
		if(window.confirm("是否确定下载 ？")){
			location.href=apis.writeWordFile+"?school_id="+schoolId+'&school_name='+schoolName;
		}
	}
})
function toUnicode(str)
{
	return escape(str).replace(/%/g,"//").toLowerCase();
}

function totext(value) {
  var array = new Uint16Array(value);	
  var blob = new Blob([array]);
  var read = new FileReader();
  read.readAsText(blob, 'utf-8');
  read.onload = function(e) {
	console.log(e.target.result)
  }
}